package com.ciaojian.client.service;

import cn.hutool.core.bean.BeanUtil;
import com.ciaojian.core.model.ProtocolUserRecord;
import com.ciaojian.core.service.ProtocolUserRecordService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * @author oxiny
 */
@Service
public class ProtocolUserRecordServiceImpl extends ProtocolUserRecordService {


    /**
     * 用户同意协议
     *
     * @param data /
     */
    @Transactional(rollbackFor = Exception.class)
    public void agree(ProtocolUserRecord data) {
        ProtocolUserRecord one = this.lambdaQuery()
                .eq(ProtocolUserRecord::getUserId, data.getUserId())
                .eq(ProtocolUserRecord::getProtocolId, data.getProtocolId())
                .one();
        ProtocolUserRecord record = Optional.ofNullable(one)
                .orElse(ProtocolUserRecord.builder().build());
        // 忽略ID拷贝
        BeanUtil.copyProperties(data,record,"id");
        this.saveOrUpdate(record);
    }
}